package org.jvnet.hudson.client_demo;

import java.util.Date;

import org.codehaus.cargo.container.deployable.Deployable;
import org.codehaus.cargo.container.deployable.WAR;
import org.codehaus.cargo.container.jboss.JBoss72xRemoteContainer;
import org.codehaus.cargo.container.jboss.JBoss7xRemoteDeployer;
import org.codehaus.cargo.container.jboss.JBoss7xRuntimeConfiguration;
import org.codehaus.cargo.container.jboss.JBossPropertySet;
import org.codehaus.cargo.container.property.GeneralPropertySet;
import org.codehaus.cargo.container.property.RemotePropertySet;

public class DeployerRemote {
	final static String WORK_HOME = "D:\\jboss\\jboss-eap-6.1\\standalone";
	final static String JBOSS_HOME = "D:\\jboss\\jboss-eap-6.1";
	static JBoss72xRemoteContainer container = null;
	static JBoss7xRuntimeConfiguration configuration = null;
	final static String USER = "jboss";
	final static String PASSWORD = "jboss1234!@#$";
	final static String IPADDR = "10.144.97.99";
	final static int MGTPORT = 9999;

	public static void main(String[] args) {

		System.out.println("Starting process...");

		try {
			
			System.out.println("開始啟動："+(new Date().getHours()) + ":" +new Date().getMinutes()+":"+new Date().getSeconds());
			prepareJBoss();

			
			JBoss7xRemoteDeployer rdp = new JBoss7xRemoteDeployer(container);
			Deployable war = new WAR("D:\\warFile\\sysflow2.war");
			 
		/*	ArrayList<Deployable> lw = new ArrayList<Deployable>();
			lw.add(war);*/

			rdp.deploy(war);
			
			System.out.println("現在時間:"+(new Date().getHours()) + ":" +new Date().getMinutes()+":"+new Date().getSeconds());
			
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	private static void prepareJBoss() throws Exception {

		/*ConfigurationFactory configurationFactory = new DefaultConfigurationFactory();
		configuration = (JBoss7xRuntimeConfiguration) configurationFactory.createConfiguration(
			        "jboss72x", ContainerType.REMOTE, ConfigurationType.RUNTIME);*/
		configuration = new JBoss7xRuntimeConfiguration();
		configuration.setProperty(GeneralPropertySet.HOSTNAME,IPADDR);
		configuration.setProperty(JBossPropertySet.JBOSS_MANAGEMENT_NATIVE_PORT, String.valueOf( MGTPORT ));
		configuration.setProperty(RemotePropertySet.USERNAME, USER );
		configuration.setProperty(RemotePropertySet.PASSWORD, PASSWORD );
		 
		container = new JBoss72xRemoteContainer( configuration);
		
	}
}
